<?php
use C\Config_App;
use I\App;
use I\DB;

class Controller {
    public function sql() {
        $db = DB::write();

        $sql    = 'SELECT id, title, caty, priority, department, status, tag, leader, author, related FROM tasks where tag = 12 limit 10';
        $tasks = $db->query($sql);

        $prioritys = App::singleton()->getconfig('worktime', 'priority');
        $users     = DB::keyBy("select id, name, department from users");
        $catys     = DB::keyBy("select * from titles where caty = " . App::singleton()->getconfig('worktime', 'caty'));
        $departments = DB::keyBy("select * from titles where caty = " . App::singleton()->getconfig('worktime', 'department'));
        $status    = App::singleton()->getconfig('worktime', 'status');
        $tags      = DB::keyBy("select id, name, pro from tags");

        foreach ($tasks as $value) {
            $value->caty = $catys[$value->caty]->name;
            $value->priority = $prioritys[$value->priority];
            $value->department = $departments[$value->department]->name;
            $value->status = $status[$value->status];
            $value->tag = $tags[$value->tag]->name;
            $value->leader = $users[$value->leader]->name;
            $value->author = $users[$value->author]->name;
            $a =  (array)$value;
            echo $value->id . ',';
            echo $value->title . ',';
            echo "\n";
        }
    }

}

